// src/main/decorator/registry.ts
export interface IpcMethodMeta {
  targetClass: any
  methodName: string
  methodKey: string
}

export class IpcRegistry {
  private static instance: IpcRegistry

  private pendingMethods: IpcMethodMeta[] = []

  static getInstance(): IpcRegistry {
    if (!this.instance) {
      this.instance = new IpcRegistry()
    }
    return this.instance
  }

  register(targetClass: any, methodName: string, methodKey: string) {
    this.pendingMethods.push({ targetClass, methodName, methodKey })
  }

  getPendingMethods(): IpcMethodMeta[] {
    return [...this.pendingMethods]
  }

  getModules(): Record<string, string[]> {
    const modules: Record<string, string[]> = {}

    for (const { targetClass, methodKey } of this.pendingMethods) {
      const module = Reflect.getMetadata('ipc:module', targetClass) || targetClass.name
      if (!modules[module]) modules[module] = []
      modules[module].push(methodKey)
    }
    return modules
  }
}
